<!--页面主要内容-->
<main class="lyear-layout-content">

    <div class="container-fluid p-t-15">

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">

                        <form method="post" class="row">
                            <div class="form-group col-md-12">
                                <label for="name">分类名称</label>
                                <input type="text" class="form-control" id="name" name="name" value=""
                                    placeholder="请输入分类名称" />
                            </div>
                            <div class="form-group col-md-12">
                                <label for="weigh">分类权重</label>
                                <input type="number" class="form-control" id="weigh" name="weigh" min="1" value=""
                                    placeholder="配置的数值" />
                            </div>
                            <div class="form-group col-md-12">
                                <button type="submit" class="btn btn-primary ajax-post"
                                    target-form="add-form">添加</button>
                                <button type="button" class="btn btn-default"
                                    onclick="javascript:history.back(-1);return false;">返 回</button>
                            </div>
                        </form>

                    </div>
                </div>
            </div>

        </div>

    </div>

</main>
<!--End 页面主要内容-->
<script>
    layui.use(['layer'], function () {
        let $ = layui.jquery,
            layer = layui.layer
        $('input[name="name"]').change(function () {
            let name = $(this).val();
            // console.log(username);
            //发起请求
            $.ajax({
                type: 'post',
                url: `{:url('admin/post/cateadd')}`,
                data: {
                    name,
                    action: "name"
                },
                dataType: 'json',
                success: function (res) {
                    if (res.code === 1) {
                        layer.msg(res.msg, { icon: 1 })
                    } else {
                        layer.msg(res.msg, { icon: 0 })
                    }
                }
            })
        })

    })
</script>